package ar.com.personalTravellers.beans;

import ar.com.personalTravellers.beans.descriptionContainer.HotelDescriptionContainer;
import com.angel.resourceBundle.propertyValue.PropertyValue;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Entity
public class Hotel extends Provider{

    @OneToMany
    private List<Room> rooms;

    @OneToMany(cascade = CascadeType.ALL)
    private List<HotelImage> images;

    @OneToOne(cascade = CascadeType.ALL)
    private HotelDescriptionContainer unoficialDescription;

    @OneToOne(cascade = CascadeType.ALL)
    private HotelDescriptionContainer oficialDescription;

    @Enumerated(value = EnumType.STRING)
    @Column(nullable = false)
    private HotelType type;

    public Hotel() {
        super();
        this.rooms = new ArrayList<Room>();
        this.images = new ArrayList<HotelImage>();
        this.unoficialDescription = new HotelDescriptionContainer(this);
        this.oficialDescription = new HotelDescriptionContainer(this);
    }

    public List<Room> getRooms() {
        return rooms;
    }

    public void setRooms(List<Room> rooms) {
        this.rooms = rooms;
    }

    public boolean containsRoom(Room room){
        return this.rooms.contains(room);
    }

    public boolean removeRoom(Room room){
        return this.rooms.remove(room);
    }

    public boolean addRoom(Room room){
        return this.rooms.add(room);
    }

    public boolean removeAllRooms(Collection<Room> rooms){
        return this.rooms.removeAll(rooms);
    }

    public boolean addAllRooms(Collection<Room> rooms){
        return this.rooms.addAll(rooms);
    }

    public boolean addImage(HotelImage hotelImage){
        return this.images.add(hotelImage);
    }

    public boolean removeImage(HotelImage hotelImage){
        return this.images.remove(hotelImage);
    }

    public HotelDescriptionContainer getOficialDescription() {
        return oficialDescription;
    }

    public void setOficialDescription(HotelDescriptionContainer oficialDescription) {
        this.oficialDescription = oficialDescription;
    }

    public HotelDescriptionContainer getUnoficialDescription() {
        return unoficialDescription;
    }

    public void setUnoficialDescription(HotelDescriptionContainer unoficialDescription) {
        this.unoficialDescription = unoficialDescription;
    }

    public void addOficialDescription(PropertyValue oficialDescription){
        this.getOficialDescription().addPropertyValue(oficialDescription);
    }

    public HotelType getType() {
        return type;
    }

    public void setType(HotelType type) {
        this.type = type;
    }

    @Override
    public String toString(){
        return this.getName() + " [ URL: " + this.getUrlAddress() + " - Type: " + this.getType().getDescription() + " - Rooms: " + this.getRooms().size() + "].";
    }

    public List<HotelImage> getImages() {
        return images;
    }

    public void setImages(List<HotelImage> images) {
        this.images = images;
    }
}